package com.hyts.infodb.zuul.web;

import com.google.common.collect.Maps;
import com.hyts.infodb.zuul.service.RefreshRouteService;
import com.hyts.infodb.zuul.service.ZuulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * project-name:infodb
 * package-name:com.hyts.infodb.zuul.web
 * author:Libo/Alex
 * create-date:2019-05-22 22:16
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: zuul 总体外置控制器
 */
@RestController
@RequestMapping("/route")
public class ZuulRouteController {

    @Autowired
    RefreshRouteService refreshRouteService;

    @Autowired
    ZuulHandlerMapping zuulHandlerMapping;

    @GetMapping("/refresh")
    public String refresh(){
        try {
            refreshRouteService.refreshRoute();
        } catch (Exception e) {
            return "failure";
        }
        return "success";
    }

    @GetMapping("/watch")
    public Map<String, Object> watch(){
        try {
            return zuulHandlerMapping.getHandlerMap();
        } catch (Exception e) {;
            return Maps.newHashMap();
        }
    }

}
